package com.hongye.area.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.hongye.area.entity.CityEntity;
import com.hongye.area.service.CityService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;



/**
 * 
 *
 * @author cyj
 * @email sunlightcs@gmail.com
 * @date 2022-04-22 16:19:01
 */
@RestController
@RequestMapping("area/city")
@CrossOrigin
public class CityController {
    @Autowired
    private CityService cityService;

    /**
     * 地区管理详细
     */
    @RequestMapping("/list/{pid}")
    public R list(@RequestParam Map<String, Object> params,@PathVariable("pid")Integer pid){
        PageUtils page = cityService.queryPage(params,pid);

        return R.ok().put("page", page).put("pid",pid);
    }

    //城市状态修改
    @RequestMapping("/updateCityState/{id}")
    public R updateCityState(@PathVariable("id")Integer id,
                             @RequestParam("state") Integer state) {
        return cityService.updateCityState(id,state);
    }

    //三级联动
    @RequestMapping("/threeLevel/{pid}")
    public R threeLevel(@PathVariable("pid")Integer pid) {
        List<CityEntity> three = cityService.threeLevel(pid);
        return R.ok().put("threeLevel",three);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		CityEntity city = cityService.getById(id);

        return R.ok().put("city", city);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody CityEntity city){
		cityService.save(city);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody CityEntity city){
		cityService.updateById(city);

        return R.ok();
    }

/*    *//**
     * 删除
     *//*
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		cityService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }*/

}
